<!--
 * @Descripttion: 出手鸭小程序
 * @version:1.0.1 
 * @Author: HHL
 * @Date: 2023-10-08 16:43:02
 * @LastEditTime: 2025-07-25 21:21:47
 * @LastEditors: sueRimn
-->

<template>
  <view>
    <scroll-view scroll-y :scroll-with-animation="true" :style="{ height: mainHeight + 'px' }"
      :scroll-into-view="scrollIntoView" class="evaluate-list">
      <!-- 估价项目 strt -->
      <evaluate-item v-for="(attrItem, attrIndex) in evaluateItems" :key="attrIndex" :attrItem="attrItem"
        :attrIndex="attrIndex" :step="step" :change="change" :valueList="valueList" @handelSelect="handelSelect"
        @handleClickChange="handleClickChange" @handleTips="handleTips" 
        :id="'attr-item-' + attrIndex"/>
      <!-- 估价项目 end -->

    </scroll-view>

    <view>
      <tip-layer
        ref="tipRef"
        :popupTipTitle="popupTipTitle"
        :popupType="popupType"
        :popupContent="popupContent"
      />
    </view>
  </view>
</template>


<script>

import SkuEvaluateItem from './SkuEvaluateItem.vue'
import EvaluateItem from './EvaluateItem.vue'
import TipLayer from './TipLayer.vue'


export default {
  components: {
    SkuEvaluateItem, EvaluateItem, TipLayer,
  },
  options: {
    styleIsolation: 'shared'
  },
  props: {
    mainHeight: { type: Number, default: 0 },
    evaluateItems: { type: Array, default: [] },
    step: { type: Number, default: 0 },
    scrollIntoView: { type: String, default: '' },
  },

  data() {
    return {
      change: -1,
      skuAttrLen: 0,

      popupTipTitle: '',
      popupType: 0,
      popupContent: {},
      valueList: [],
    }
  },

  methods: {
    handelSelect(type,attrId,evaluateType, valueItem) {
      let _step = this.step
      valueItem.attrId = attrId
      valueItem.evaluateType = evaluateType
      if (this.change == -1) {
        if (!type) {
          _step++
          this.valueList.push(valueItem)
        } else {
          let attrIds = this.valueList.map(item => { return item.valueId });
          let _index = attrIds.indexOf(valueItem.valueId)
          if (_index !== -1) {
            this.valueList.splice(_index, 1);
          } else {
            this.valueList.push(valueItem)
          }
        }
      } else {
        this.valueList[this.change] = valueItem
        this.change = -1
      }
      this.$emit('onEvaluateClick', _step, this.valueList)
    },

    // 修改答案
    handleClickChange(index) {
      if (this.change === index) {
        this.change = -1
      } else {
        this.change = index
      }
    },
    // 提示
    handleTips(tip) {
      console.log('tip', tip)
      // console.log(this.$refs)
      // this.popupTipTitle = tip.title
      this.popupContent = tip.popupContent
      this.popupType = tip.popupType
      this.$refs.tipRef.onOpen()
    },
  },
}
</script>